package com.boot.webflux.security.example2.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@Component
public class CloudUserDetailsService  implements ReactiveUserDetailsService {
    @Override
    public Mono<UserDetails> findByUsername(String username) {
        log.info("---UserDetailsService----;username:"+username);
        List<GrantedAuthority> authorities =  Stream.of(new SimpleGrantedAuthority("ROLE_admin" )).collect(Collectors.toList());
        return Mono.just(new User( "admin",new BCryptPasswordEncoder().encode("123456"),authorities));
    }
}
